package com.vodlee.flowlayoutdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;

import com.vodlee.flowlayoutlib.FlowLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private FlowLayout flowLayout;
    private ArrayList<String> textArray;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        flowLayout = findViewById(R.id.flowLayout);

        initData();
        initLayout();
    }

    private void initData() {
        textArray = new ArrayList<>();
        textArray.add("abc");
        textArray.add("精灵宝可梦");
        textArray.add("pokemon");
        textArray.add("哆啦A梦");
        textArray.add("Random Door");
        textArray.add("Harry potter");
        textArray.add("the Goblet of Fire");
        textArray.add("Phoenix is a kind of bird");
        textArray.add("the Deathly Hallows");
        textArray.add("Cat");
        textArray.add("川建国");
    }

    private void initLayout() {
        for (int i = 0; i < textArray.size(); i++) {
            TextView view = new TextView(this);
            view.setText(textArray.get(i));
            view.setBackgroundResource(R.drawable.common_text_bg);
            FlowLayout.FlowLayoutParams params = new FlowLayout.FlowLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            view.setLayoutParams(params);
            flowLayout.addView(view);
        }
    }
}